package svc

import (
	"github.com/casbin/casbin/v2"
	"gorm.io/gorm"
	"yangming-college/app/usercenter/cmd/v1/rpc/internal/config"
	"yangming-college/common/initialize"
)

type ServiceContext struct {
	Config   config.Config
	DB       *gorm.DB
	Enforcer *casbin.Enforcer
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:   c,
		DB:       initialize.DBinit(c.Mysql.Account, c.Mysql.Password, c.Mysql.Host, c.Mysql.Database),
		Enforcer: initialize.NewCasbinAdapter(c.Mysql.Account, c.Mysql.Password, c.Mysql.Host, c.Mysql.Database),
	}
}
